package com.ctgu.j08.controller;

import com.ctgu.j08.service.FactoryService;
import com.ctgu.j08.vo.DUser;
import com.ctgu.j08.vo.Factory;
import com.ctgu.j08.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @date: 2021/5/28 21:24
 */
@Controller
@RequestMapping("/fac")
public class FactoryController {
    @Autowired
    private FactoryService factoryService;

    @PostMapping("/add")
    @ApiOperation("添加厂家")
    @ResponseBody
    public Result addFactory(@RequestBody Factory factory){
        System.out.println("添加的工厂"+factory);
        return factoryService.addFactory(factory);
    }

    @PutMapping("/edit")
    @ApiOperation("更新厂家信息")
    @ResponseBody
    public Result editFactory(@RequestBody Factory factory)
    {
        return factoryService.editFactory(factory);
    }

    @DeleteMapping("/del/{facId}")
    @ApiOperation("根据厂家id删除厂家")
    @ResponseBody
    public Result delFactoryById(@PathVariable("facId") int facId){
        System.out.println("删除Controller");
        return factoryService.delFactoryById(facId);
    }

    @GetMapping("/getAll")
    @ApiOperation("获取全部厂家信息")
    @ResponseBody
    public Result getAllFactoryInfo()
    {
        return factoryService.getAllFactoryInfo();
    }

    @GetMapping("/searchOne/{facName}")
    @ApiOperation("查询厂家信息")
    @ResponseBody
    public Result searchFacInfo(@PathVariable("facName") String facName)
    {
        System.out.println("查询厂家Controller");
        return factoryService.searchFactoryByName(facName);
    }
}
